package com.dao;

import com.bean.History;
import com.bean.HistoryReturn;
import com.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @ClassName HistoryDao
 * @Desc TODO
 * @Author xiaoding
 * @Date 2021/1/13 19:20
 * @Version 1.0
 */

public class HistoryDao {

    /*
     * @Author historySelect
     * @Description 返回所有图书借阅信息
     * @Date 19:28 2021/1/13
     * @Param historyReturn
     * @return java.util.List<com.bean.History>
     */
    public List<History> historySelect(HistoryReturn historyReturn) {
        SqlSession session = MyBatisUtils.getSqlSession();
        String sql = "com.resources.HistoryMapping.historySelect";
        List<History> list = session.selectList(sql,historyReturn);
        return list;
    }

    /*
     * @Author historySearch
     * @Description 根据图书名称搜索借阅信息
     * @Date 19:33 2021/1/13
     * @Param historyReturn
     * @return java.util.List<com.bean.History>
     */
    public List<History> historySearch(HistoryReturn historyReturn) {
        SqlSession session = MyBatisUtils.getSqlSession();
        String sql = "com.resources.HistoryMapping.historySearch";
        List<History> list = session.selectList(sql,historyReturn);
        return list;
    }

    /*
     * @Author historyCount
     * @Description 返回图书借阅信息的数量
     * @Date 19:40 2021/1/13
     * @Param HistoryReturn
     * @return int
     */
    public int historyCount(HistoryReturn historyReturn) {
        SqlSession session = MyBatisUtils.getSqlSession();
        String sql = "com.resources.HistoryMapping.historyCount";
        int a = session.selectOne(sql,historyReturn);
        return a;
    }

    /*
     * @Author isBookBorrow
     * @Description 判断当前书籍是否以借阅
     * @Date 10:42 2021/1/17
     * @Param historyReturn
     * @return com.bean.History
     */
    public History isBookBorrow(HistoryReturn historyReturn) {
        SqlSession session = MyBatisUtils.getSqlSession();
        String sql = "com.resources.HistoryMapping.isBookBorrow";
        History history = session.selectOne(sql,historyReturn);
        return history;
    }

    /*
     * @Author historySelectCount
     * @Description 根据图书名称返回借阅信息
     * @Date 20:03 2021/1/13
     * @Param historyReturn
     * @return int
     */
    public int historySearchCount(HistoryReturn historyReturn) {
        SqlSession session = MyBatisUtils.getSqlSession();
        String sql = "com.resources.HistoryMapping.historySearchCount";
        int a = session.selectOne(sql,historyReturn);
        return a;
    }

    /*
     * @Author addHistory
     * @Description 添加图书借阅信息
     * @Date 20:06 2021/1/13
     * @Param history
     * @return int
     */
    public int addHistory(History history) {
        SqlSession session = MyBatisUtils.getSqlSession();
        String sql = "com.resources.HistoryMapping.addHistory";
        int a = session.insert(sql,history);
        session.commit();
        return a;
    }

    /*
     * @Author historyReturn
     * @Description 归还书籍
     * @Date 20:11 2021/1/13
     * @Param historyReturn
     * @return int
     */
    public int historyReturn(HistoryReturn historyReturn) {
        SqlSession session = MyBatisUtils.getSqlSession();
        String sql = "com.resources.HistoryMapping.historyReturn";
        int a = session.update(sql,historyReturn);
        session.commit();
        return a;
    }
}
